<?php

/**
 * This is the model class for table "price_types".
 *
 * The followings are the available columns in table 'price_types':
 * @property integer $PTP_ID
 * @property string $PTP_NAME
 */
class PriceTypes extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return PriceTypes the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'price_types';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('PTP_NAME', 'required'),
			array('PTP_NAME', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('PTP_ID, PTP_NAME', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'PTP_ID' => 'ID',
			'PTP_NAME' => 'Название',
		);
	}
	
	/**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('PTP_ID',$this->PTP_ID);
        $criteria->compare('PTP_NAME',$this->PTP_NAME,true);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
	
	protected function beforeDelete()
	{
		if(parent::beforeDelete())
		{
			Price::model()->deleteAllByAttributes(array('PRI_PTP_ID' => $this->PTP_ID));
			return true;
		}
		return false;
	}
}